package com.sc.nft.service.impl;

import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.collection.CollUtil;
import com.sc.nft.dao.ReportOverviewDao;
import com.sc.nft.entity.ReportOverview;
import com.sc.nft.entity.dto.ReportSaveDTO;
import com.sc.nft.entity.vo.ReportOverviewVO;
import com.sc.nft.service.ReportOverviewService;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 后台报表总览(ReportOverview)表服务实现类
 *
 * @author wwc
 * @since 2023-04-13 14:43:35
 */
@Slf4j
@RequiredArgsConstructor
@Service
public class ReportOverviewServiceImpl implements ReportOverviewService {

    private final ReportOverviewDao reportOverviewDao;

    @Override
    public Boolean save(ReportSaveDTO reportSaveDTO) {
        if (BeanUtil.isEmpty(reportSaveDTO)) {
            return false;
        }
        ReportOverview report = new ReportOverview();
        BeanUtil.copyProperties(reportSaveDTO, report);
        return report.insert();
    }

    @Override
    public Boolean saveBath(List<ReportSaveDTO> reportSaves) {

        if (CollUtil.isEmpty(reportSaves)) {
            return false;
        }
        List<ReportOverview> reportSave = CollUtil.newArrayList();
        reportSaves.forEach(reportOverview -> {
            ReportOverview report = new ReportOverview();
            BeanUtil.copyProperties(reportOverview, report);
            reportSave.add(report);
        });
        return reportOverviewDao.insertBatch(reportSave);
    }

    @Override
    public Boolean saveBathEntity(List<ReportOverview> reportSaves) {
        return reportOverviewDao.insertBatch(reportSaves);
    }

    /**
     * 根据天数和类型获取对应多少天前的数据
     *
     * @param day
     * @param codes
     * @return
     */
    @Override
    public List<ReportOverviewVO> obtainTheDataOfThePreviousDaysBasedOnTheDaysAndTypes(Integer day, List<Integer> codes) {
        return reportOverviewDao.obtainTheDataOfThePreviousDaysBasedOnTheDaysAndTypes(day, codes);
    }

}
